import request from "@/utils/request";
import {
  absototalForm,
  absototalInfo,
  absototalPageVO,
  absototalQuery,
} from "./model";

const USER_BASE_URL = "/absototal";

class Abso_totalAPI {
  /**
   * 获取分页列表
   *
   * @param queryParams 查询参数
   * @returns 分页列表
   */
  static getPage(queryParams: absototalQuery) {
    return request<any, ResponseData<absototalPageVO[]>>({
      url: `${USER_BASE_URL}/get_page_all`,
      method: "get",
      params: queryParams,
    });
  }

  /**
   * 获取表单详情
   *
   * @param userId ID
   * @returns 表单详情
   */
  static getPage2(queryParams: absototalQuery) {
    return request<any, absototalForm>({
      url: `${USER_BASE_URL}/get_total`,
      method: "get",
      params: queryParams,
    });
  }

  /**
   * 添加
   *
   * @param data 表单数据
   * @returns 请求结果
   */
  static add(data: absototalInfo) {
    return request({
      url: `${USER_BASE_URL}/add`,
      method: "post",
      data: data,
    });
  }

  /**
   * 修改
   *
   * @param id ID
   * @param data 表单数据
   * @returns 请求结果
   */
  static update(id: number | string, data: absototalInfo) {
    return request({
      url: `${USER_BASE_URL}/edit?id=${id}`,
      method: "post",
      data: data,
    });
  }

  /**
   * 批量删除，多个以英文逗号(,)分割
   *
   * @param ids ID字符串，多个以英文逗号(,)分割
   * @returns 请求结果
   */
  static deleteByIds(ids: string) {
    return request({
      url: `${USER_BASE_URL}/delete?id=${ids}`,
      method: "post",
    });
  }

  /**
   * 下载导入模板
   *
   * @returns 导入模板文件
   */
  static downloadTemplate() {
    return request({
      url: `${USER_BASE_URL}/template`,
      method: "get",
      responseType: "arraybuffer",
    });
  }

  /**
   * 导出
   *
   * @param queryParams 查询参数
   * @returns 导出文件
   */
  static export(queryParams: absototalQuery) {
    return request({
      url: `${USER_BASE_URL}/export_total`,
      method: "post",
      params: queryParams,
      responseType: "arraybuffer",
    });
  }

  /**
   * 导入
   *
   * @param deptId 部门ID
   * @param file 导入文件
   * @returns 请求结果
   */
  static import(deptId: number, file: File) {
    const formData = new FormData();
    formData.append("file", file);
    return request({
      url: `${USER_BASE_URL}/import`,
      method: "post",
      params: { deptId: deptId },
      data: formData,
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  }
}

export default Abso_totalAPI;
